/*
 * @lc app=leetcode.cn id=232 lang=cpp
 *
 * [232] 用栈实现队列
 */

// @lc code=start
class MyQueue {
private:
    //使用两个栈 (入、出) 来实现队列
    std::stack<int> InStack;    //默认进栈

    //出栈时, 当出栈队列为空, 为了获得第一个元素, 需要将入栈元素全部输入至出栈栈中
    std::stack<int> OutStack;
public:
    MyQueue() {

    }
    
    void push(int x) {
        InStack.push(x);
    }
    
    int pop() {
        int result;
        if (OutStack.size() > 0) {
            result = OutStack.top();
            OutStack.pop();
            return result;
        }

        while (InStack.size() > 0) {
            OutStack.push(InStack.top());
            InStack.pop();
        }

        result = OutStack.top();
        OutStack.pop();
        return result;
    }
    
    int peek() {
        if (OutStack.size() > 0)
            return OutStack.top();

        while (InStack.size() > 0) {
            OutStack.push(InStack.top());
            InStack.pop();
        }

        return OutStack.top();
    }
    
    bool empty() {
        return !(InStack.size() + OutStack.size() > 0);
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */
// @lc code=end

